﻿/********************************************************************************/
/* 	0724th - screen.d															*/
/*------------------------------------------------------------------------------*/
/*	製作		（　゜ワ゜）ノ　／　松久貫太									*/
/*	製作開始　	2007/05/11														*/
/*	MAIL		omega@personal.email.ne.jp										*/
/*	URL		http://nagoya.cool.ne.jp/o_mega										*/
/*																				*/
/*	このソースは「やらわかライセンス」の元で配布されています。					*/
/*-更新履歴---------------------------------------------------------------------*/
/*	2007/--/--																	*/
/*-その他-----------------------------------------------------------------------*/
/*	なし																		*/
/********************************************************************************/

/* ライブラリのインポート *******************************************************/
private import hell2;
private import opengl;
private import vector;


/* 変換行列の操作 ***************************************************************/

void glTranslatef(float x,float y,float z)
{
	opengl.glTranslatef(x,y,z);
}

void glRotatef(float x,float y,float z)
{
	opengl.glRotatef(x,1,0,0);
	opengl.glRotatef(y,0,1,0);
	opengl.glRotatef(z,0,0,1);
}

void glLoadIdentity()
{
	opengl.glLoadIdentity();
}

void glPushMatrix()
{
	opengl.glPushMatrix();
}

void glPopMatrix()
{
	opengl.glPopMatrix();
}

void glColor4f(float r,float g,float b,float a)
{
	opengl.glColor4f(r,g,b,a);
}

void glScalef(float x,float y,float z)
{
	opengl.glScalef(x,y,z);
}


/* Shape ************************************************************************/
class Shape{
public:
	static void draw()
	{
	/*
	float SIDEWALL_WIDTH = 128.0f
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0 , 640 , 480 , 0 , -1 , 1);
	glMatrixMode(GL_MODELVIEW);
	
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.25f, 0.25f, 0.25f, 0.5f);
    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(0, 0, 0);
    glVertex3f(SIDEWALL_WIDTH, 0, 0);
    glVertex3f(SIDEWALL_WIDTH, 480, 0);
    glVertex3f(0, 480, 0);
    glEnd();
    glBegin(GL_TRIANGLE_FAN);
    glVertex3f(640, 0, 0);
    glVertex3f(640 - SIDEWALL_WIDTH, 0, 0);
    glVertex3f(640 - SIDEWALL_WIDTH, 480, 0);
    glVertex3f(640, 480, 0);
    glEnd();
    glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
    glBegin(GL_LINES);
    glVertex3f(SIDEWALL_WIDTH, 0, 0);
    glVertex3f(SIDEWALL_WIDTH, 480, 0);
    glVertex3f(640 - SIDEWALL_WIDTH, 0, 0);
    glVertex3f(640 - SIDEWALL_WIDTH, 480, 0);
    glEnd();
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    
    
	glMatrixMode(GL_PROJECTION);
    setPerspective();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    */
    /*
    	static int timer = 0;
    	timer++;
    	glPushMatrix();
    	glTranslatef(0,0,-10.0f);
    	opengl.glRotatef(cast(float)timer / 1.0f , 1 , 0 , 0);
    	opengl.glRotatef(cast(float)timer / 0.7f , 0 , 1 , 0);
    	opengl.glRotatef(cast(float)timer / 1.1f , 0 , 0 , 1);
    	glColor4f(0.5f,0.0f,1.0f,0.5f);
    	
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f 	,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f 	,1.0f	,1.0f	);
		glEnd();
		
		glLineWidth(1);
		glColor4f(1.0f,1.0f,1.0f,0.8f);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
		glBegin(GL_LINES);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
		
		glPopMatrix();
		*/
		drawWire();
		drawPolygon();
	}
	
	static void drawWire()
	{
	}
	
	static void drawPolygon()
	{
	}
}


/* BulletShape ******************************************************************/

class BulletShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
		glBegin(GL_LINES);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
	}
	
	static void drawPolygon()
	{
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f 	,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f 	,1.0f	,1.0f	);
		glEnd();
	}
}


/* ParticleShape ***************************************************************/

class TriangleShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(1);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1		,0			,0	);
		glVertex3f(0.5		,0.86603	,0	);
		glVertex3f(0.5		,-0.86603	,0	);
		glEnd();
	}
	
	static void drawPolygon()
	{
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(-1		,0			,0	);
		glVertex3f(0.5		,0.86603	,0	);
		glVertex3f(0.5		,-0.86603	,0	);
		glEnd();
	}
}

/* LineShape ***************************************************************/
class LineShape : Shape
{
public:
	static void drawWire(Vec3 v1,Vec3 v2)
	{
		glLineWidth(2);
		glBegin(GL_LINES);
		glVertex3f(v1.x		,v1.y		,v1.z	);
		glVertex3f(v2.x		,v2.y		,v2.z	);
		glEnd();
	}
}

/* CubeShape ***************************************************************/
class CubeShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,3	);
		glVertex3f(-3		,3			,3	);
		glVertex3f(-3		,-3			,3	);
		glVertex3f( 3		,-3			,3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,1	);
		glVertex3f(-3		,3			,1	);
		glVertex3f(-3		,-3			,1	);
		glVertex3f( 3		,-3			,1	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,-1	);
		glVertex3f(-3		,3			,-1	);
		glVertex3f(-3		,-3			,-1	);
		glVertex3f( 3		,-3			,-1	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,-3	);
		glVertex3f(-3		,3			,-3	);
		glVertex3f(-3		,-3			,-3	);
		glVertex3f( 3		,-3			,-3	);
		glEnd();
		
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,3	);
		glVertex3f(-3		,3			,3	);
		glVertex3f(-3		,3			,-3	);
		glVertex3f( 3		,3			,-3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,1			,3	);
		glVertex3f(-3		,1			,3	);
		glVertex3f(-3		,1			,-3	);
		glVertex3f( 3		,1			,-3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,-1			,3	);
		glVertex3f(-3		,-1			,3	);
		glVertex3f(-3		,-1			,-3	);
		glVertex3f( 3		,-1			,-3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,-3			,3	);
		glVertex3f(-3		,-3			,3	);
		glVertex3f(-3		,-3			,-3	);
		glVertex3f( 3		,-3			,-3	);
		glEnd();
		
		glBegin(GL_LINE_LOOP);
		glVertex3f( 3		,3			,3	);
		glVertex3f( 3		,3			,-3	);
		glVertex3f( 3		,-3			,-3	);
		glVertex3f( 3		,-3			,3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 1		,3			,3	);
		glVertex3f( 1		,3			,-3	);
		glVertex3f( 1		,-3			,-3	);
		glVertex3f( 1		,-3			,3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1		,3			,3	);
		glVertex3f(-1		,3			,-3	);
		glVertex3f(-1		,-3			,-3	);
		glVertex3f(-1		,-3			,3	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f(-3		,3			,3	);
		glVertex3f(-3		,3			,-3	);
		glVertex3f(-3		,-3			,-3	);
		glVertex3f(-3		,-3			,3	);
		glEnd();
	}
}

/* HexShape ***************************************************************/
class HexShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		,0.8661916	,-1	);
		glVertex3f( 1.0		,0.0		,-1	);
		glVertex3f( 0.5		,-0.8661916	,-1	);
		glVertex3f(-0.5		,-0.8661916	,-1	);
		glVertex3f(-1.0		,0.0		,-1	);
		glVertex3f(-0.5		,0.8661916	,-1	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		,0.8661916	,1	);
		glVertex3f( 1.0		,0.0		,1	);
		glVertex3f( 0.5		,-0.8661916	,1	);
		glVertex3f(-0.5		,-0.8661916	,1	);
		glVertex3f(-1.0		,0.0		,1	);
		glVertex3f(-0.5		,0.8661916	,1	);
		glEnd();
		
		glBegin(GL_LINES);
		glVertex3f( 0.5		,0.8661916	,-1	);
		glVertex3f( 0.5		,0.8661916	,1	);
		glVertex3f( 1.0		,0.0		,-1	);
		glVertex3f( 1.0		,0.0		,1	);
		glVertex3f( 0.5		,-0.8661916	,-1	);
		glVertex3f( 0.5		,-0.8661916	,1	);
		glVertex3f(-0.5		,-0.8661916	,-1	);
		glVertex3f(-0.5		,-0.8661916	,1	);
		glVertex3f(-1.0		,0.0		,-1	);
		glVertex3f(-1.0		,0.0		,1	);
		glVertex3f(-0.5		,0.8661916	,-1	);
		glVertex3f(-0.5		,0.8661916	,1	);
		glEnd();
	}
}